import { get, post, del, put } from '@/utils/request'

// 权限相关API
export const getPermissions = (params) => {
  return get('/permission/sys-client/api/sysPermission/list?' + new URLSearchParams(params).toString())
}

export const addPermission = (params) => {
  return post('/permission/sys-client/api/sysPermission/add', params)
}

export const deletePermission = (id) => {
  return del(`/permission/sys-client/api/sysPermission/delete/${id}`)
}

export const updatePermission = (id, params) => {
  return put(`/permission/sys-client/api/sysPermission/update/${id}`, params)
}

// 角色相关API
export const getRoles = (params) => {
  return get('/permission/sys-client/api/sysRole/list?' + new URLSearchParams(params).toString())
}

export const addRole = (params) => {
  return post('/permission/sys-client/api/sysRole/add', params)
}

export const deleteRole = (id) => {
  return del(`/permission/sys-client/api/sysRole/delete/${id}`)
}

export const updateRole = (id, params) => {
  return put(`/permission/sys-client/api/sysRole/update/${id}`, params)
}


// 角色权限分配API
export const getRolePermissions = (roleId) => {
  return get(`/permission/sys-client/api/sysRolePermission/getPermissions/${roleId}`)
}

export const assignRolePermissions = (params) => {
  return post('/permission/sys-client/api/sysRolePermission/bind', params)
}

export const unassignRolePermissions = (params) => {
  return post('/permission/sys-client/api/sysRolePermission/unbind', params)
}

// 用户相关API

export const getUsers = (params) => {
  return get('/user/user-client/api/sysUser/list?' + new URLSearchParams(params).toString())
}

export const addUser = (params) => {
  return post('/user/user-client/api/sysUser/add', params)
}


export const deleteUser = (id) => {
  return del(`/user/user-client/api/sysUser/delete/${id}`)
}

export const updateUser = (id, params) => {
  return put(`user/user-client/api/sysUser/update/${id}`, params)
}




// 用户角色分配API
export const getUserRoles = (userId) => {
  return get(`/permission/sys-client/api/sysUserRole/user/${userId}/roles`)
}

export const assignUserRoles = (userId, roleId) => {
  return post('/permission/sys-client/api/sysUserRole/replaceRole', {
    userId: userId,
    roleId: roleId
  })
}
export const deleteUserRoleByUserId = (userId) => {
  return del(`/permission/sys-client/api/sysUserRole/delete/${userId}`)
}


export const getRoleUsers = (roleId) => {
  return get(`/permission/sys-client/api/sysUserRole/role/${roleId}/users`);
}
